* Multiproduct Firms, Horizontal Mergers, and International Trade
* Jackie M.L. Chan, Michael Irlacher, and Michael Koch

* This do file runs additional regressions for domestic market outcomes.

* Setup
use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_vars_dom_product_cn8plus.dta", clear

* Drop if either acquirer or target has no products before (because guaranteed to be no overlap)
drop if nprod_before==0 | nprodT==0

* Use shares besides ranks
egen sumvrdA_before = sum(vrdA_before), by(cvrnrA aar)
gen shareA_before = vrdA_before/sumvrdA_before
gen shareA_before_overlap = shareA_before if vrdA_before!=. & vrdT_before!=.

egen sumvrdT_before = sum(vrdT_before), by(cvrnrA aar)
gen shareT_before = vrdT_before/sumvrdT_before
gen shareT_before_overlap = shareT_before if vrdA_before!=. & vrdT_before!=.

gen shareAT_before = shareA_before*shareT_before
gen shareA_beforesq = shareA_before^2
gen shareT_beforesq = shareT_before^2

collapse (sum) shareAT_before shareA_beforesq shareT_beforesq, by(cvrnrA aar)

*Bloom et al. 2013 measure
gen sicij = shareAT_before/shareA_beforesq^0.5/shareT_beforesq^0.5
sum sicij, d
local med = r(p50)

tempfile tempfile1
save `tempfile1.dta', replace

* Main data
use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\regression_data_domestic.dta", clear

merge m:1 cvrnrA aar using `tempfile1.dta', keepusing(sicij) keep(match master) nogen
egen msicij = mean(sicij), by(cvrnrA)

* Figure A.17(a), (b), (c)
foreach x in lnnprod{
did_imputation `x' group_cvrnr aarA aar3 if minemployee_cvrnr>=10 & ((acquirer==1 & msicij>`med' & msicij!=.) | acquirer==0), fe(group_cvrnr aarA) hor(0/2) pretrend(4) tol(0.0001) maxit(250) autosample cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_figureA17.txt", bdec(4) sdec(4) nocons nonotes

did_imputation `x' group_cvrnr aarA aar3 if minemployee_cvrnr>=10 & ((acquirer==1 & msicij<=`med') | acquirer==0), fe(group_cvrnr aarA) hor(0/2) pretrend(4) tol(0.0001) maxit(250) autosample cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_figureA17.txt", bdec(4) sdec(4) nocons nonotes 
}

foreach x in lnnprodAT_nodup{	
did_imputation `x' group_cvrnr aarA aar3 if minemployee_cvrnr>=10 & ((acquirer==1 & ((nprodT>0 & d_yr<=0) | d_yr>0) & msicij>`med' & msicij!=.) | acquirer==0), fe(group_cvrnr aarA) hor(0/2) pretrend(4) tol(0.0001) maxit(250) autosample cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_figureA17.txt", bdec(4) sdec(4) nocons nonotes 

did_imputation `x' group_cvrnr aarA aar3 if minemployee_cvrnr>=10 & ((acquirer==1 & ((nprodT>0 & d_yr<=0) | d_yr>0) & msicij<=`med') | acquirer==0), fe(group_cvrnr aarA) hor(0/2) pretrend(4) tol(0.0001) maxit(250) autosample cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_figureA17.txt", bdec(4) sdec(4) nocons nonotes 
}

foreach x in theil_fy{
did_imputation `x' group_cvrnr aarA aar3 if minemployee_cvrnr>=10 & ((acquirer==1 & msicij>`med' & msicij!=.) | acquirer==0), fe(group_cvrnr aarA) hor(0/2) pretrend(4) tol(0.0001) maxit(250) autosample cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_figureA17.txt", bdec(4) sdec(4) nocons nonotes 

did_imputation `x' group_cvrnr aarA aar3 if minemployee_cvrnr>=10 & ((acquirer==1 & msicij<=`med') | acquirer==0), fe(group_cvrnr aarA) hor(0/2) pretrend(4) tol(0.0001) maxit(250) autosample cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_figureA17.txt", bdec(4) sdec(4) nocons nonotes 
}
